/**
 * 
 */
package com.zwl.security_authorize.service.impl;

import com.zwl.security_authorize.domain.Admin;
import com.zwl.security_authorize.domain.Resource;
import com.zwl.security_authorize.dto.ResourceInfo;
import com.zwl.security_authorize.repository.AdminRepository;
import com.zwl.security_authorize.repository.ResourceRepository;
import com.zwl.security_authorize.service.ResourceService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
* @author zengweilulu javatom
 * *
 */
@Service
@Transactional
public class ResourceServiceImpl implements ResourceService {
	
	@Autowired
	private ResourceRepository resourceRepository;
	@Autowired
	private AdminRepository adminRepository;

	/* (non-Javadoc)
	 * @see com.idea.ams.service.ResourceService#getResourceTree(java.lang.Long, com.idea.ams.domain.Admin)
	 */
	@Override
	public ResourceInfo getTree(Long adminId) {
//		Admin admin = adminRepository.findOne(adminId);
//		return resourceRepository.findByName("根节点").toTree(admin);
		return  null;
	}

	/* (non-Javadoc)
	 * @see com.zwl.security_authorize.service.ResourceService#getInfo(java.lang.Long)
	 */
	@Override
	public ResourceInfo getInfo(Long id) {
//		Resource resource = resourceRepository.findOne(id);
//		ResourceInfo resourceInfo = new ResourceInfo();
//		BeanUtils.copyProperties(resource, resourceInfo);
//		return resourceInfo;
		return  null;
	}

	@Override
	public ResourceInfo create(ResourceInfo info) {
//		Resource parent = resourceRepository.findOne(info.getParentId());
//		if(parent == null){
//			parent = resourceRepository.findByName("根节点");
//		}
//		Resource resource = new Resource();
//		BeanUtils.copyProperties(info, resource);
//		parent.addChild(resource);
//		info.setId(resourceRepository.save(resource).getId());
//		return info;
return  null;
	}

	@Override
	public ResourceInfo update(ResourceInfo info) {
//		Resource resource = resourceRepository.findOne(info.getId());
//		BeanUtils.copyProperties(info, resource);
//		return info;
		return  null;
	}

	@Override
	public void delete(Long id) {
//		resourceRepository.delete(id);
	}
	/* (non-Javadoc)
	 * @see com.zwl.security_authorize.service.ResourceService#move(java.lang.Long, boolean)
	 */
	@Override
	public Long move(Long id, boolean up) {
//		Resource resource = resourceRepository.findOne(id);
//		int index = resource.getSort();
//		List<Resource> childs = resource.getParent().getChilds();
//		for (int i = 0; i < childs.size(); i++) {
//			Resource current = childs.get(i);
//			if(current.getId().equals(id)) {
//				if(up){
//					if(i != 0) {
//						Resource pre = childs.get(i - 1);
//						resource.setSort(pre.getSort());
//						pre.setSort(index);
//						resourceRepository.save(pre);
//					}
//				}else{
//					if(i != childs.size()-1) {
//						Resource next = childs.get(i + 1);
//						resource.setSort(next.getSort());
//						next.setSort(index);
//						resourceRepository.save(next);
//					}
//				}
//			}
//		}
//		resourceRepository.save(resource);
		//return resource.getParent().getId();
		return  null;
	}

}
